<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogVisible"
    width="1080px"
    top="5vh"
  >
    <div class="form-table">
      <div class="tips tips-danger">
        <div>
          <strong>注意：系统查询的快递信息可能有延迟并信息被精简,如有需要请到各个快递官方网站查询!</strong>
        </div>
      </div>
    </div>

    <el-row v-if="log!=null">
      <table id="queryResult" class="result-info" cellspacing="0">
        <tbody>
        <tr v-for="item in log.data" :key="item.context" :class="{last:item.isLast}">
          <td class="row1"><span class="day">{{item.ftime}}</span></td>
          <td :class="{status:true,statuscheck:item.checked,statusfirst:item.isFirst,statuswait:item.isWait}">
            <div v-if="item.isFirst!=true" class="col2">
              <span class="step">
                <span class="line1"></span>
                <span class="line2"></span>
              </span>
            </div>
          </td>
          <td class="context">{{item.context}}</td>
        </tr>
        </tbody>
      </table>
    </el-row>
    <div v-else class="no-info">
      <strong>注意：快递公司录入肯定存在时间差，如果没有查到请过一段时间查询或请到快递官方网站查询!</strong>
    </div>

    <div slot="footer" style="text-align: center">
      <el-button type="primary" @click="closed"> 关闭</el-button>
    </div>
  </el-dialog>
</template>

<style>
  .el-dialog {
    z-index: 0;
  }

  .tips {
    position: relative;
    padding: .75rem 1.25rem;
    margin-bottom: 1rem;
    border: 1px solid transparent;
    border-radius: .25rem;
    font-size: 12px;
  }

  .tips-danger {
    color: #721c24;
    background-color: #f8d7da;
    border-color: #f5c6cb;
  }

  .result-info {
    font-size: 12px;
  }

  .queryRight {
    float: right;
    margin-right: 10px;
  }

  .status {
    width: 18px;
    height: 18px;
    background: url("/src/assets/imgs/spider_search_v4.png") 1px -783px no-repeat;
  }

  .result-info td {
    padding: 6px;
    color: #828282;
    /*border-bottom: 1px solid #d2d2d2;
      background-color: #f5f5f5*/
  }

  .result-info .status {
    width: 30px;
    background: url("/src/assets/imgs/spider_search_v4.png") 13px -764px no-repeat;
  }

  .result-info-down .status {
    width: 30px;
    background: url("/src/assets/imgs/spider_search_v4.png") -30px -764px no-repeat;
  }

  .result-info .statusfirst {
    background: url("/src/assets/imgs/spider_search_v4.png") 13px -804px no-repeat;
  }

  .result-info .statuscheck {
    background: url("/src/assets/imgs/spider_search_v4.png") 10px -717px no-repeat;
  }

  .result-info .statuswait {
    background: url("/src/assets/imgs/spider_search_v4.png") -30px -802px no-repeat;
  }

  .status .col2 {
    position: relative;
    z-index: -1;
  }

  .status .line1 {
    position: absolute;
    left: 7px;
    width: 0.57em;
    height: 5em;
    border-right: 0.08em solid #d2d2d2;
    top: -5px;
    z-index: -1;
  }

  .day {
    display: block;
  }

  .time {
    font-size: 16px;
  }

  .result-info .last td, .result-info .last td a {
    color: #ff7800;
    border-bottom: none;
  }

  .result-info td a:hover {
    color: #3278e6;
  }

  .result-info .row1 {
    width: 105px;
    text-align: center;
    padding-left: 14px;
    padding-right: 0;
  }


</style>

<script>
  import FrontService from 'src/service/front'
  import Dialog from 'src/components/common/js/dialog-mix'

  export default {
    name: 'HPostLogDialog',
    mixins: [Dialog],
    data() {
      return {
        log: null
      }
    },
    watch: {
      value(current, old) {
        if (current != null) {
          this.getDatas()
        } else {
          this.log = null
        }
      }
    },
    props: {
      value: {
        type: Object,
        default: {}
      }
    },
    methods: {
      getDatas: function () {
        const me = this
        if (me.value != null) {
          FrontService.expressLog(me.value.code, me.value.post).then(ds => {
            if (ds != null) {
              const data = ds.datas[0]
              me.initData(data)
              me.log = data
            }
          })
        }
      },
      initData: function (data) {
        let checked = false;
        if (data.state == 3) {
          checked = true;
        }
        const length = data.data.length;
        for (let i = 0; i < length; i++) {
          if (i == 0) {
            data.data[i].isLast = true;
            if (checked) {
              data.data[i].checked = true
              data.data[i].isWait = false
            } else {
              data.data[i].checked = false
              data.data[i].isWait = true
            }
          } else {
            data.data[i].isLast = false
            data.data[i].checked = false
            data.data[i].isWait = false
          }
          if ((i + 1) == length) {
            data.data[i].isFirst = true
            data.data[i].checked = false
            data.data[i].isWait = false
          } else {
            data.data[i].isFirst = false
          }
        }

      }
    },
    beforeMount: function () {
      this.getDatas()
    }
  }
</script>
